package com.wwz.activiti;

import com.wwz.activiti.pojo.Holiday;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 流程变量测试
 * @create: 2021-04-08 14:04:40
 * @author:wwz
 */
public class VariableTest {
    public static void main(String[] args) {
//        //1.流程部署
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        //1.1 得到repositoryService
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//
//        //1.2部署
//        Deployment deploy = repositoryService.createDeployment()
//                .addClasspathResource("diagram/holiday4.bpmn")
//                .addClasspathResource("diagram/holiday4.png")
//                .name("请假流程-流程变量")
//                .deploy();
//
//        System.out.println(deploy.getId());
//        System.out.println(deploy.getName());


        //=================================================

        //1.启动流程实例
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        //1.1得到runtimeService
//        RuntimeService runtimeService = processEngine.getRuntimeService();
//        //流程定义的key myProcess_1
//        String key = "myProcess_1";
//        //1.2
//        Map<String, Object> map = new HashMap<String, Object>();
//        Holiday holiday = new Holiday();
//        holiday.setNum(5F);
//        map.put("holiday",holiday);
//
//        //启动流程实例并且设置流程变量的值
//        //影响表ACT_GE_BYTEARRAY   ACT_RU_VARIABLE
//        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key,map);
//
//        System.out.println(processInstance.getName());
//        System.out.println(processInstance.getProcessDefinitionId());

        //=================================================

        //完成任务
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        TaskService taskService = processEngine.getTaskService();

        String key = "myProcess_1";
        Task task = taskService.createTaskQuery().processDefinitionKey(key).taskAssignee("zhangliu").singleResult();
        if(task != null){
            taskService.complete(task.getId());
            System.out.println("任务执行完毕");
        }

    }


}
